from models import db


class Roles(db.Model):
    """角色表"""
    __tablename__ = "tb_role"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, doc='角色id')
    name = db.Column(db.String(256), doc='角色的名字')
    permission = db.relationship('PerModel', secondary='role_permission', backref=db.backref('per_role'))
    vip = db.relationship('VIP', backref='vip_role')


class PerModel(db.Model):
    __tablename__ = 'tb_permission'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, doc='权限id')
    name = db.Column(db.String(256), doc='权限路径')


role_permission = db.Table(
    'role_permission',
    db.Column('role_id', db.Integer, db.ForeignKey("tb_role.id")),
    db.Column('permission_id', db.Integer, db.ForeignKey("tb_permission.id"))
)
